/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.service.job;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserResume;
import com.thinkgem.jeesite.modules.hk.sys.dao.job.HkUserResumeDao;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserResumeEducational;
import com.thinkgem.jeesite.modules.hk.sys.dao.job.HkUserResumeEducationalDao;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserResumeExperience;
import com.thinkgem.jeesite.modules.hk.sys.dao.job.HkUserResumeExperienceDao;

/**
 * 用户简历Service
 * @author 罗天文
 * @version 2018-06-15
 */
@Service
@Transactional(readOnly = true)
public class HkUserResumeService extends CrudService<HkUserResumeDao, HkUserResume> {

	@Autowired
	private HkUserResumeEducationalDao hkUserResumeEducationalDao;
	@Autowired
	private HkUserResumeExperienceDao hkUserResumeExperienceDao;
	
	public HkUserResume get(String id) {
		HkUserResume hkUserResume = super.get(id);
		hkUserResume.setHkUserResumeEducationalList(hkUserResumeEducationalDao.findList(new HkUserResumeEducational(hkUserResume)));
		hkUserResume.setHkUserResumeExperienceList(hkUserResumeExperienceDao.findList(new HkUserResumeExperience(hkUserResume)));
		return hkUserResume;
	}
	
	public List<HkUserResume> findList(HkUserResume hkUserResume) {
		return super.findList(hkUserResume);
	}
	
	public Page<HkUserResume> findPage(Page<HkUserResume> page, HkUserResume hkUserResume) {
		return super.findPage(page, hkUserResume);
	}
	
	@Transactional(readOnly = false)
	public void save(HkUserResume hkUserResume) {
		super.save(hkUserResume);
		for (HkUserResumeEducational hkUserResumeEducational : hkUserResume.getHkUserResumeEducationalList()){
			if (hkUserResumeEducational.getId() == null){
				continue;
			}
			if (HkUserResumeEducational.DEL_FLAG_NORMAL.equals(hkUserResumeEducational.getDelFlag())){
				if (StringUtils.isBlank(hkUserResumeEducational.getId())){
					hkUserResumeEducational.setResume(hkUserResume);
					hkUserResumeEducational.preInsert();
					hkUserResumeEducationalDao.insert(hkUserResumeEducational);
				}else{
					hkUserResumeEducational.preUpdate();
					hkUserResumeEducationalDao.update(hkUserResumeEducational);
				}
			}else{
				hkUserResumeEducationalDao.delete(hkUserResumeEducational);
			}
		}
		for (HkUserResumeExperience hkUserResumeExperience : hkUserResume.getHkUserResumeExperienceList()){
			if (hkUserResumeExperience.getId() == null){
				continue;
			}
			if (HkUserResumeExperience.DEL_FLAG_NORMAL.equals(hkUserResumeExperience.getDelFlag())){
				if (StringUtils.isBlank(hkUserResumeExperience.getId())){
					hkUserResumeExperience.setResume(hkUserResume);
					hkUserResumeExperience.preInsert();
					hkUserResumeExperienceDao.insert(hkUserResumeExperience);
				}else{
					hkUserResumeExperience.preUpdate();
					hkUserResumeExperienceDao.update(hkUserResumeExperience);
				}
			}else{
				hkUserResumeExperienceDao.delete(hkUserResumeExperience);
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(HkUserResume hkUserResume) {
		super.delete(hkUserResume);
		hkUserResumeEducationalDao.delete(new HkUserResumeEducational(hkUserResume));
		hkUserResumeExperienceDao.delete(new HkUserResumeExperience(hkUserResume));
	}
	
}